package com.chiao.action.admin;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chiao.core.BaseController;

@Controller
@RequestMapping(value="/admin")
public class DesktopAction extends BaseController{
	
	@RequestMapping(value="/desktop")
	public String desktop(){
		return "admin/desktop";
	}

	@RequestMapping(value="/module/{path}")
	public String redirectPath(@PathVariable String path){
		return "admin/module/"+path;
	}
	
	@RequestMapping(value="/serverInfo")
	public @ResponseBody Map<String,Object> getServerInfo(HttpServletRequest request) throws UnknownHostException{
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("a.操作系统", System.getProperty("os.name") + "_" + System.getProperty("os.arch"));
		map.put("b.主机IP", InetAddress.getLocalHost().getHostAddress());
		map.put("c.应用服务器", request.getSession().getServletContext().getServerInfo());
		map.put("d.监听端口", request.getServerPort());
		map.put("e.Web根路径", request.getSession().getServletContext().getRealPath("/"));
		map.put("f.Servlet版本", request.getSession().getServletContext().getMajorVersion() + "." + request.getSession().getServletContext().getMinorVersion());
		map.put("g.JVM版本", System.getProperty("java.version"));
		map.put("h.JVM提供商", System.getProperty("java.vendor"));
		map.put("i.JVM安装路径", System.getProperty("java.home"));
		map.put("j.最大可分配内存", Runtime.getRuntime().maxMemory() / 1024 / 1024 + "M");
		map.put("k.已分配总内存", Runtime.getRuntime().totalMemory() / 1024 / 1024 + "M");
		map.put("l.已用内存", new Double((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024).intValue() + "M");
		return map;
	}
}
